/**
 * Opening Window
 */
package View;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;


/**
 * This class is the first panel of the game. Allows player to start a new game, load
 * an old game, or exit
 * @author Whitney
 * @version 1.0
 */
public class SplashWindow extends JPanel {

	/**
	 * Panel Buttons
	 */
	private final JButton btnNew, btnLoad, btnExit;

	/**
	 * Panel Label
	 */
	private final JLabel lblImage;

	/**
	 * Panel Return Initial
	 */
	private int splCh = -1;

	/**
	 * Splash Screen Image
	 */
	private final ImageIcon planet = new ImageIcon ("images/SplashScreenImage.png");

	/**
	 * The constructor for the original JPanel of the game
	 * @param loadOption toggles the load button on 
	 * 	and off depending on wether there's a saved game
	 */
	public SplashWindow(boolean loadOption) {
		
		final ButtonListener listen = new ButtonListener();
		
		setBackground(Color.BLACK);
		final GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{90, 0, 0, 100, 0, 0};
		gridBagLayout.rowHeights = new int[]{130, 0, 29, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]
				{0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]
				{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);

//Possible Space Image
		lblImage = new JLabel("", planet, SwingConstants.CENTER);
		final GridBagConstraints gbc_lblImage = new GridBagConstraints();
		gbc_lblImage.insets = new Insets(0, 0, 5, 5);
		gbc_lblImage.gridx = 1;
		gbc_lblImage.gridy = 0;
		add(lblImage, gbc_lblImage);
		
		btnNew = new JButton("New Game");
		btnNew.setFont(new Font("Krungthep", Font.PLAIN, 13));
		final GridBagConstraints gbc_btnNew = new GridBagConstraints();
		gbc_btnNew.insets = new Insets(0, 0, 5, 5);
		gbc_btnNew.gridx = 1;
		gbc_btnNew.gridy = 2;
		add(btnNew, gbc_btnNew);
		btnNew.addActionListener(listen);
		
		btnLoad = new JButton("Load Game");
		btnLoad.setFont(new Font("Krungthep", Font.PLAIN, 13));
		btnLoad.setEnabled(loadOption); //grays out load option if there are no saved games
		final GridBagConstraints gbc_btnLoad = new GridBagConstraints();
		gbc_btnLoad.insets = new Insets(0, 0, 5, 5);
		gbc_btnLoad.gridx = 1;
		gbc_btnLoad.gridy = 3;
		add(btnLoad, gbc_btnLoad);
		btnLoad.addActionListener(listen);
		
		btnExit = new JButton("     Exit      ");
		btnExit.setFont(new Font("Krungthep", Font.PLAIN, 13));
		final GridBagConstraints gbc_btnExit = new GridBagConstraints();
		gbc_btnExit.insets = new Insets(0, 0, 5, 5);
		gbc_btnExit.gridx = 1;
		gbc_btnExit.gridy = 4;
		add(btnExit, gbc_btnExit);
		btnExit.addActionListener(listen);
		
	}

	/**
	 * Button listeners for SplashWindow
	 * @author Whitney
	 */
	private class ButtonListener implements ActionListener{
		/**
		 * Handles button press events
		 * @param event The button press event
		 */
		public void actionPerformed (ActionEvent event){
			if(event.getSource().equals(btnNew)){
				splCh = 0;
				System.out.println(splCh);
				System.out.println("New");
			}
			else if(event.getSource().equals(btnLoad)){
				splCh = 1;
				System.out.println(splCh);
				System.out.println("Load");
			}
			else if(event.getSource().equals(btnExit)){
				splCh = 2;
				System.out.println(splCh);
				System.exit(0);
			}
		}

		/**
		 * The toString for the ButtonListener
		 * @return Returns a space because the button 
		 * listener doesn't need a toString. 
		 * */
		public String toString(){
			return "";
		}
	}
	
	/**
	 * Returns the value of the button selected! Either:
	 * New Game - 0
	 * Load Game - 1
	 * Exit - 2
	 * @return the integer value of the button choice
	 */
	public int getSplashChoice(){
		return splCh;
	}

}
